package cn.com.ddapp.ddm.ui.mine;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.ypy.eventbus.EventBus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import butterknife.BindView;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.mine.MyEvent;
import cn.com.ddapp.ddm.fragment.base.mine.CouponsListFragment;
import cn.com.ddapp.ddm.widget.viewpager.ViewPagerIndicator;

public class CouponsActivity extends BaseActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.titletext)
    TextView titletext;
    @BindView(R.id.viewpger_coupons)
    ViewPager mViewPager;
    @BindView(R.id.viewpager_indicator_coupons)
    ViewPagerIndicator mIndicator;

    private List<String> mTabTitles;
    private FragmentPagerAdapter mAdapter;
    private List<Fragment> mTabFragments = new ArrayList<Fragment>();

    @Override
    public void initView() {
        mViewPager.setOffscreenPageLimit(3);
        mTabTitles = Arrays.asList(getString(R.string.coupons_unused),
                getString(R.string.coupons_uesd),getString(R.string.coupons_overdue));
        mIndicator = (ViewPagerIndicator)findViewById(R.id.viewpager_indicator_coupons);
        // 设置Tab上的标题
        mIndicator.setTabItemTitles(mTabTitles);
        for (int i=0; i<mTabTitles.size();i++) {
            CouponsListFragment fragment = CouponsListFragment
                    .newInstance(i);
            mTabFragments.add(fragment);
        }
        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public int getCount() {
                return mTabFragments.size();
            }

            @Override
            public Fragment getItem(int position) {
                return mTabFragments.get(position);
            }
        };
        mViewPager.setAdapter(mAdapter);
        // 设置关联的ViewPager
        mIndicator.setViewPager(mViewPager, 0);
        titletext.setText(BaseApplication.getIntstance().getResources().getString(R.string.my_coupons));
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mIndicator.setOnPageChangeListener(new ViewPagerIndicator.PageChangeListener() {
            //正在滑动
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {
                 EventBus.getDefault().post(new MyEvent());
            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_coupons;
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }

}
